package com.common.utils;


import java.security.MessageDigest;

import org.apache.log4j.Logger;

/**
 * MD5 data encrypt util
 */
public class MD5Crypt{

    private static Logger logger = Logger.getLogger(MD5Crypt.class);

    /**
     * @deprecated MD5 has no decrypt method
     */
    public String decrypt(String cryptogram) {
        throw new UnsupportedOperationException("MD5 has no decrypt method!");
    }

    /**
     * encrypt data
     */
    public static String encrypt(String clearText) {
        String encryptedPassword = null;
        try {
            // specify a message digest algorithm
            MessageDigest digest = MessageDigest.getInstance("MD5");

            // digest message
            digest.update(clearText.getBytes());
            Base64Encoder encoder = new Base64Encoder(System.out);

            // encode digested message using Base64 encoder
            encryptedPassword = encoder.encode(digest.digest());

        }
        catch (Exception e) {
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }
        return encryptedPassword;
    }
    
    public static void main(String[] args) {
    	 System.out.println(encrypt("111111"));
	}

}
